home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 36
/
Amiga Format CD36 (1999-01-22)(Future Publishing)(GB)[!][issue 1999-02].iso
/
-seriously_amiga-
/
graphics
/
gfx3d.library
/
examples
/
moto.e
< prev
Wrap
Text File
|
1998-12-12
|
12KB
|
533 lines
MODULE 'gfx3d',
'libraries/gfx3d'
MODULE 'exec/memory',
'graphics/gfx',
'graphics/view',
'intuition/screens'
CONST WIDTH = 320,
HEIGHT = 200
PROC main ()
DEF raster : LONG
DEF bitmap : PTR TO bitmap
DEF newscreen : PTR TO ns
DEF screen : PTR TO screen
DEF env, camera : LONG
DEF moto : LONG
DEF i, k : LONG
DEF points, polygons : PTR TO INT
DEF startsec, startmic : LONG
DEF seconds, micros : LONG
DEF view : PTR TO view
DEF viewport : PTR TO viewport
DEF joy : REG
DEF x, y, v, vmax, a, d, ac, dec : LONG
DEF sn, cs : LONG
DEF piega, maxp, treshp : LONG
DEF fps : LONG
newscreen := [ 0 , 0 ,
WIDTH , HEIGHT ,
8 ,
0 , 1 ,
0 ,
CUSTOMSCREEN OR CUSTOMBITMAP ,
0 ,
'E screen...' ,
0 , 0 ] : ns
points := [
-4, 6, -4,
-4, 9, -5,
-4, 7, -17,
-4, 6, -17,
0, 4, -9,
0, 0, -13,
0, 0, -19,
0, 4, -23,
0, 10, -23,
0, 14, -19,
0, 14, -13,
0, 10, -9,
-3, 13, -14,
0, 11, -14,
3, 13, -14,
-3, 13, -18,
0, 11, -18,
3, 13, -18,
-3, 9, -22,
0, 9, -20,
3, 9, -22,
-3, 5, -22,
0, 5, -20,
3, 5, -22,
-3, 1, -18,
0, 3, -18,
3, 1, -18,
-3, 1, -14,
0, 3, -14,
3, 1, -14,
-3, 5, -10,
-3, 9, -10,
0, 5, -12,
3, 5, -10,
3, 9, -10,
0, 9, -12,
0, 5, 21,
0, 3, 19,
0, 3, 15,
0, 5, 13,
0, 9, 13,
0, 11, 15,
0, 9, 21,
0, 11, 19,
-2, 13, 19,
2, 13, 19,
0, 14, 20,
-2, 13, 15,
2, 13, 15,
0, 14, 14,
-2, 9, 11,
2, 9, 11,
0, 10, 10,
-2, 5, 11,
2, 5, 11,
0, 4, 10,
-2, 1, 15,
2, 1, 15,
0, 0, 14,
-2, 1, 19,
2, 1, 19,
0, 0, 20,
-2, 5, 23,
-2, 9, 23,
2, 9, 23,
2, 5, 23,
0, 4, 24,
0, 10, 24,
2, 19, -23,
-2, 19, -23,
1, 21, -25,
-1, 21, -25,
3, 17, -15,
-3, 17, -15,
4, 19, -16,
2, 22, -16,
-2, 22, -16,
-4, 19, -16,
3, 12, -5,
2, 15, -7,
-3, 12, -5,
-2, 15, -7,
4, 20, 8,
3, 21, -4,
3, 15, 0,
0, 17, -7,
5, 11, -2,
-5, 11, -2,
-3, 15, 0,
-4, 20, 8,
-3, 21, -4,
0, 2, -8,
0, 2, 10,
-5, 6, 0,
-4, 8, 10,
-5, 16, 15,
-5, 18, 7,
0, 18, 20,
-6, 19, 16,
-4, 24, 18,
-3, 28, 12,
-6, 27, 8,
6, 19, 16,
5, 18, 7,
5, 6, 0,
4, 6, -4,
4, 8, 10,
5, 16, 15,
4, 24, 18,
3, 28, 12,
6, 27, 8 ] : INT
polygons := [ 143,
4, 3, 2, 1, 0, 15,
4, 3, 0, 1, 2, 15,
4, 11, 4, 33, 34, 5,
4, 31, 30, 4, 11, 5,
4, 4, 5, 29, 33, 5,
4, 30, 27, 5, 4, 5,
4, 5, 6, 26, 29, 5,
4, 27, 24, 6, 5, 5,
4, 6, 7, 23, 26, 5,
4, 24, 21, 7, 6, 5,
4, 7, 8, 20, 23, 5,
4, 21, 18, 8, 7, 5,
4, 8, 9, 17, 20, 5,
4, 18, 15, 9, 8, 5,
4, 9, 10, 14, 17, 5,
4, 15, 12, 10, 9, 5,
4, 10, 11, 34, 14, 5,
4, 12, 31, 11, 10, 5,
4, 12, 13, 35, 31, 10,
4, 13, 14, 34, 35, 10,
4, 15, 16, 13, 12, 10,
4, 16, 17, 14, 13, 10,
4, 18, 19, 16, 15, 10,
4, 19, 20, 17, 16, 10,
4, 21, 22, 19, 18, 10,
4, 22, 23, 20, 19, 10,
4, 24, 25, 22, 21, 10,
4, 25, 26, 23, 22, 10,
4, 27, 28, 25, 24, 10,
4, 28, 29, 26, 25, 10,
4, 30, 32, 28, 27, 10,
4, 32, 33, 29, 28, 10,
4, 31, 35, 32, 30, 10,
4, 35, 34, 33, 32, 10,
4, 42, 64, 65, 36, 10,
4, 63, 42, 36, 62, 10,
4, 36, 65, 60, 37, 10,
4, 62, 36, 37, 59, 10,
4, 37, 60, 57, 38, 10,
4, 59, 37, 38, 56, 10,
4, 38, 57, 54, 39, 10,
4, 56, 38, 39, 53, 10,
4, 39, 54, 51, 40, 10,
4, 53, 39, 40, 50, 10,
4, 40, 51, 48, 41, 10,
4, 50, 40, 41, 47, 10,
4, 41, 48, 45, 43, 10,
4, 47, 41, 43, 44, 10,
4, 43, 45, 64, 42, 10,
4, 44, 43, 42, 63, 10,
4, 44, 63, 67, 46, 5,
4, 46, 67, 64, 45, 5,
4, 47, 44, 46, 49, 5,
4, 49, 46, 45, 48, 5,
4, 50, 47, 49, 52, 5,
4, 52, 49, 48, 51, 5,
4, 53, 50, 52, 55, 5,
4, 55, 52, 51, 54, 5,
4, 56, 53, 55, 58, 5,
4, 58, 55, 54, 57, 5,
4, 59, 56, 58, 61, 5,
4, 61, 58, 57, 60, 5,
4, 62, 59, 61, 66, 5,
4, 66, 61, 60, 65, 5,
4, 63, 62, 66, 67, 5,
4, 67, 66, 65, 64, 5,
4, 80, 78, 105, 0, 7,
3, 0, 105, 91, 7,
3, 104, 78, 86, 15,
3, 105, 78, 104, 15,
3, 80, 93, 87, 15,
3, 0, 93, 80, 15,
4, 80, 81, 79, 78, 7,
4, 89, 98, 102, 82, 7,
4, 102, 98, 99, 108, 7,
3, 102, 110, 108, 12,
3, 98, 99, 101, 12,
3, 110, 109, 108, 9,
4, 99, 108, 109, 100, 9,
3, 101, 99, 100, 9,
3, 78, 86, 104, 15,
3, 80, 93, 87, 15,
3, 103, 82, 102, 15,
3, 96, 98, 89, 15,
3, 84, 82, 103, 15,
3, 88, 96, 89, 15,
3, 84, 103, 86, 15,
3, 87, 96, 88, 15,
3, 78, 84, 86, 15,
3, 80, 87, 88, 15,
4, 73, 72, 79, 81, 14,
4, 69, 68, 72, 73, 14,
4, 71, 70, 68, 69, 12,
3, 68, 74, 72, 14,
3, 69, 73, 77, 14,
3, 75, 74, 68, 12,
3, 69, 77, 76, 12,
3, 70, 75, 68, 12,
3, 71, 69, 76, 12,
4, 76, 75, 70, 71, 12,
4, 76, 77, 74, 75, 12,
3, 73, 81, 77, 5,
3, 72, 74, 79, 5,
3, 85, 74, 77, 5,
3, 79, 74, 85, 5,
3, 81, 85, 77, 5,
3, 79, 85, 84, 14,
3, 79, 84, 78, 14,
3, 81, 88, 85, 14,
3, 81, 80, 88, 14,
3, 84, 83, 82, 12,
3, 84, 85, 83, 12,
3, 90, 88, 89, 12,
3, 85, 88, 90, 12,
4, 89, 82, 83, 90, 12,
3, 85, 90, 83, 12,
3, 104, 92, 91, 14,
3, 91, 92, 93, 14,
3, 91, 105, 104, 14,
3, 91, 93, 0, 14,
3, 86, 103, 104, 12,
3, 87, 93, 96, 12,
4, 106, 107, 95, 94, 5,
3, 92, 106, 94, 5,
3, 107, 97, 95, 14,
3, 107, 106, 104, 12,
3, 107, 104, 103, 12,
3, 93, 95, 96, 12,
3, 93, 94, 95, 12,
3, 92, 104, 106, 12,
3, 107, 102, 97, 14,
3, 103, 102, 107, 14,
3, 97, 102, 108, 12,
3, 102, 108, 110, 12,
3, 110, 108, 109, 9,
3, 101, 100, 99, 9,
3, 98, 101, 99, 12,
3, 97, 99, 98, 12,
3, 96, 95, 98, 14,
3, 95, 97, 98, 14,
3, 92, 94, 93, 12,
3, 97, 108, 99, 12,
4, 99, 100, 109, 108, 9 ] : INT
IF gfx3dbase := OpenLibrary ( 'gfx3d.library' , 0 )
IF raster := AllocMem ( WIDTH*HEIGHT , MEMF_CHIP OR MEMF_CLEAR )
IF bitmap := AllocMem ( SIZEOF bitmap , MEMF_PUBLIC )
InitBitMap ( bitmap , 8 , WIDTH , HEIGHT )
FOR k:=0 TO 7
bitmap.planes[k] := raster+(k*WIDTH/8*HEIGHT)
ENDFOR
newscreen.custombitmap := bitmap
IF screen := OpenScreen ( newscreen )
view := ViewAddress()
viewport := view.viewport
SetRGB4( viewport , 0 , 0 , 0 , 0 )
SetRGB4( viewport , 5 , 4 , 4 , 4 )
SetRGB4( viewport , 7 , 12 , 12 , 12 )
SetRGB4( viewport , 9 , 1 , 14 , 15 )
SetRGB4( viewport , 10 , 14 , 4 , 1 )
SetRGB4( viewport , 12 , 5 , 0 , 15 )
SetRGB4( viewport , 14 , 12 , 8 , 4 )
SetRGB4( viewport , 15 , 14 , 14 , 14 )
GfXBegin ( GFX_ENVIRONMENT )
GfXBegin ( GFX_OBJECT )
GfXFrame ( buildframe ( points , polygons , GfXFlt( 10 ) , 0 ) )
GfXPosition ( 0 , 512 , 0 )
moto := GfXEnd ()
GfXObject ( moto )
env := GfXEnd ()
GfXBegin ( GFX_CAMERA )
GfXWidth ( WIDTH )
GfXHeight ( HEIGHT )
GfXVideoBuffer ( raster )
GfXEnvironment ( env )
GfXFocus ( 256 )
GfXAspectRatio ( GfXDiv( GfXFlt( 320 ) , GfXFlt( WIDTH ) ) ,
GfXFlt( 1 ) ,
GfXDiv( GfXFlt( 200 ) , GfXFlt( HEIGHT ) ) )
GfXPosition( 0 , -100 , 300 )
GfXDirection ( -10 , 0 , 0 )
camera := GfXEnd ()
k := 0
i := 0
x := 0
y := 512
v := 0
vmax := 200
piega := 0
maxp := 32
treshp := 16
CurrentTime ( {startsec} , {startmic} )
fps := 5
REPEAT
a := 50 / fps
d := 50 / fps
ac := 150 / fps
dec := 50 / fps
joy := readjoystick( 1 )
IF joy AND 4
piega := piega + a
IF piega > maxp THEN piega := maxp
ELSE
IF piega > 0
piega := piega - d
IF piega < 0 THEN piega := 0
ENDIF
ENDIF
IF joy AND 8
piega := piega - a
IF piega < (-maxp) THEN piega := -maxp
ELSE
IF piega < 0
piega := piega + d
IF piega > 0 THEN piega := 0
ENDIF
ENDIF
IF joy AND 1
v := v + ac
IF v > vmax THEN v := vmax
ENDIF
IF joy AND 2
v := v - 4
ENDIF
v := v - dec
IF v < 0 THEN v := 0
IF ( (v > 0) AND ( ( piega > treshp ) OR ( piega < (-treshp) ) ) ) THEN i := i - ( piega / 3 )
sn := GfXSin( GfXFixMul( i , GfXDiv( GfXFlt( 128 ) , GfXPi() ) ) )
cs := GfXCos( GfXFixMul( i , GfXDiv( GfXFlt( 128 ) , GfXPi() ) ) )
x := x - GfXFltMul( sn , v )
y := y + GfXFltMul( cs , v )
GfXModifyObjectPosition ( moto , x , y , 0 )
GfXModifyObjectDirection ( moto ,
-GfXFltMul( sn , piega ),
GfXFltMul( cs , piega ),
i )
GfXUpdateScene ( camera )
WaitTOF ()
GfXUpdateVideoBuffer ()
GfXClearWorkBuffer ()
INC k
CurrentTime ( {seconds} , {micros} )
seconds := seconds - startsec
IF seconds <= 0 THEN seconds := 1
IF k > seconds
fps := k / seconds
ELSE
fps := 1
ENDIF
UNTIL readjoystick( 1 ) >= 16
Delay ( 50 )
CloseScreen ( screen )
ENDIF
FreeMem ( bitmap , SIZEOF bitmap )
ENDIF
FreeMem ( raster , WIDTH*HEIGHT )
ENDIF
CloseLibrary ( gfx3dbase )
ENDIF
ENDPROC
PROC buildframe ( points : PTR TO INT , polygons : PTR TO INT ,
scale : LONG , offset : LONG )
DEF i, k : LONG
DEF count : LONG
DEF n : LONG
DEF index : LONG
DEF color : LONG
DEF x, y, z : LONG
DEF x0, y0, z0 : LONG
DEF x1, y1, z1 : LONG
GfXBegin ( GFX_FRAME )
count := polygons[0]
index := 1
FOR k:=1 TO count
n := polygons[ index ]
INC index
color := polygons[ index+n ]
GfXSetColor ( color+offset )
x0 := GfXFltMul( scale , points[ polygons[ index ] * 3 ] )
y0 := GfXFltMul( scale , points[ polygons[ index ] * 3 + 1 ] )
z0 := GfXFltMul( scale , points[ polygons[ index ] * 3 + 2 ] )
x1 := GfXFltMul( scale , points[ polygons[ index+1 ] * 3 ] )
y1 := GfXFltMul( scale , points[ polygons[ index+1 ] * 3 + 1 ] )
z1 := GfXFltMul( scale , points[ polygons[ index+1 ] * 3 + 2 ] )
i := 2
WHILE i < n
GfXBegin ( GFX_POLYGON )
GfXVertex ( x0 , z0 , y0 )
x := GfXFltMul( scale , points[ polygons[ index+i ] * 3 ] )
y := GfXFltMul( scale , points[ polygons[ index+i ] * 3 + 1 ] )
z := GfXFltMul( scale , points[ polygons[ index+i ] * 3 + 2 ] )
INC i
GfXVertex ( x , z , y )
GfXVertex ( x1 , z1 , y1 )
GfXPolygon ( GfXEnd () )
IF i < n
x1 := x
y1 := y
z1 := z
ENDIF
ENDWHILE
index := index+n+1
ENDFOR
RETURN GfXEnd ()
ENDPROC
PROC readjoystick ( joynum : LONG )
DEF ret : REG
DEF joy : REG
DEF read : REG
DEF hardware : PTR TO INT
DEF leftbutton : PTR TO CHAR
MOVEQ #0,ret
IF joynum=0
hardware := $DFF00A
ELSE
hardware := $DFF00C
ENDIF
joy := hardware[0]
MOVE.W joy,read
LSR.W #1,read
EOR.W joy,read
IF read AND $0100 THEN ret := 1
IF read AND $0001 THEN ret := ret + 2
IF joy AND $0002 THEN ret := ret + 4
IF joy AND $0200 THEN ret := ret + 8
leftbutton := $BFE001
joy := leftbutton[]
NOT.W joy
IF joynum = 0
IF joy AND $0040 THEN ret := ret + 16
ELSE
IF joy AND $0080 THEN ret := ret + 16
ENDIF
ENDPROC ret
/*EE folds
-1
438 47 441 37
EE folds*/